\newif\iftextversion \textversionfalse
\newif\iffull \fullfalse
\newif\ifdraft  \drafttrue

\IfFileExists{texdirectives.tex}
   {\input{texdirectives}}
   {\typeout{== ERROR == The dynamically generated file `texdirectives.tex' couldn't be found. You should use `make` to build the manual for Unison (`unison-manual.pdf'). Don't call latex directly.}\stop}
\input{texdirectives}
\input{unisonversion}

\newcommand{\finish}[1]{\ifdraft{\ifhevea\red\else \large\bf\fi [#1]\ifhevea\fi}\fi}
\newcommand{\finishlater}[1]{}
\newcommand{\fortrevor}[1]{}

\newcommand{\CLIENT}{\iftextversion CLIENT \else {\em client}\fi}
\newcommand{\SERVER}{\iftextversion SERVER \else {\em server}\fi}

\newcommand{\showtt}[1]{%
  \ifhevea
    \iftextversion
      "#1"%
    \else
      {\large\tt #1}%
    \fi
  \else
    {\tt #1}%
  \fi
}

\makeatletter
\def\@opentoc#1{\begingroup
  \makeatletter
  \if@filesw \expandafter\newwrite\csname tf@#1\endcsname
             \immediate\openout \csname tf@#1\endcsname \jobname.#1\relax
  \fi \global\@nobreakfalse \endgroup}
\newcommand{\TABLEOFCONTENTS}{%
  \ifhevea
    \iftextversion\else
      \section*{Contents}
      \begin{quote}
      \input{unison-manual.htoc}
      \end{quote}
    \fi
  \else
    \@opentoc{htoc}
    \tableofcontents
  \fi
}
\makeatother

\newcommand{\SNIP}[2]{%
\ifhevea\iftextversion
\begin{rawhtml}<pre>----SNIP----\end{rawhtml}
#1
#2 %
\begin{rawhtml}</pre>\end{rawhtml}%
\fi\fi
}

\newcommand{\sectionref}[2]{%
\ifhevea
  \iftextversion
    the section ``#2''
  \else
    the \url{##1}{#2} section%
  \fi
\else
  Section~\ref{#1} {[#2]}%
\fi
}

\newcommand{\bcpurl}[1]{\url{#1}}

\newcommand{\urlref}[2]{\bcpurl{##1}{#2}}
\newcommand{\ONEURL}[1]{%
  \iftextversion#1\else{\def~{\symbol{"7E}}\oneurl{#1}}\fi}
\newcommand{\URL}[2]{%
  \iftextversion#2 (#1)\else\bcpurl{#1}{#2}\fi}
\newcommand{\SHOWURL}[2]{%
  \ifhevea\URL{#1}{#2}\else#2\footnote{{\def~{\symbol{"7E}}\tt #1}}\fi}

% Usage: \SECTION{Title and menu item name}{tex label}{man section id}
\newcommand{\SECTION}[3]{%
  \ifhevea
    \SNIP{#1}{#3}%
    \iftextversion\else \@print{<hr>}\fi%
    \section*{\label{#2}#1}%
  \else
    \newpage
    \section{\label{#2}#1}%
    \addtocontents{htoc}{{\string\large\string\bf\string\urlref{#2}{#1}}\\}%
  \fi
}

\newcommand{\SUBSECTION}[2]{%
  \ifhevea
    \subsection*{\label{#2}#1}%
  \else
    \subsection{\label{#2}#1}%
    \addtocontents{htoc}{\hspace{10em}\bullet\string\urlref{#2}{#1}\\}
  \fi
}

\newcommand{\SUBSUBSECTION}[2]{%
  \ifhevea
    \subsubsection*{\label{#2}#1}%
  \else
    \subsubsection{\label{#2}#1}%
    \addtocontents{htoc}{\hspace{18em}\string\urlref{#2}{#1}\\}
  \fi
}

\newcommand{\TOPSUBSECTION}[2]{%
  \ifhevea\SNIP{#1}{#2}\fi
  \SUBSECTION{#1}{#2}%
}

% The quote-based macros looks a imperfect, perhaps due to the lack of
% alignment
% \newenvironment{textui}{{\em Textual Interface:}\begin{quote}}{\end{quote}}
% \newenvironment{tkui}{{\em Graphical Interface:}\begin{quote}}{\end{quote}}
\newenvironment{textui}{\medskip{\em Textual Interface:}\begin{itemize}\item[]
  }{\end{itemize}}
\newenvironment{tkui}{\medskip{\em Graphical Interface:}\begin{itemize}\item[]
  }{\end{itemize}}
\newenvironment{changesfromversion}[1]{%
  \noindent Changes since #1:
  \begin{itemize}
}{
  \end{itemize}
}

\newcommand{\incompatible}{%
  \iftextversion
    INCOMPATIBLE CHANGE:
  \else
    {\bf Incompatible change:}
  \fi}

\newcommand{\UNISONUSERS}{\URL{mailto:unison-users@yahoogroups.com}{{\tt
      unison-users@yahoogroups.com}}}
\newcommand{\UNISONHACKERS}{\URL{mailto:unison-hackers@lists.seas.upenn.edu}{{\tt
      unison-hackers@lists.seas.upenn.edu}}}

\ifhevea
 \makeatletter
 \let\oldmeta=\@meta
 \renewcommand{\@meta}{%
 \oldmeta
\ifdraft
 \begin{rawhtml}
 <META name="Author" content="Benjamin C. Pierce">
 <link rel="stylesheet" href="/home/bcpierce/pub/unison/unison.css">
 \end{rawhtml}
\else
 \begin{rawhtml}
 <META name="Author" content="Benjamin C. Pierce">
 <link rel="stylesheet" href="http://www.cis.upenn.edu/~bcpierce/unison/unison.css">
 \end{rawhtml}
\fi
}
 \makeatother
\fi
